using System;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Threading;
using Phoenix.Diagnostics;
using Phoenix.Events;
using Phoenix.Framework;
using Phoenix.Storage;

namespace Phoenix
{
    public class PhoenixHost : IPhoenixHost
    {
        public PhoenixHost(
            IPhoenixHostTarget hostTarget, 
            IViewLocator viewLocator,
            IControllerLocator controllerLocator, 
            ITransientStore applicationTransientState, 
            IErrorReporter errorReporter, 
            IActionInvoker actionInvoker,
#if WINDOWS_PHONE
            Tasks.ITaskManager taskManager,
#endif
            Dispatcher uiDispatcher,
            TaskScheduler taskScheduler)
        {
            ActionInvoker = actionInvoker;
            AppDispatcher = uiDispatcher;
            AppScheduler = taskScheduler;
            ErrorReporter = errorReporter;
            ApplicationTransientState = applicationTransientState;
            ControllerLocator = controllerLocator;
            ViewLocator = viewLocator;
            HostTarget = hostTarget;
#if WINDOWS_PHONE
            TaskManager = taskManager;
#endif
            EventAggregator = new EventAggregator(new EventAggregator.Config());
        }

        public IPhoenixHostTarget HostTarget { get; private set; }

        public void RegisterAssembly(Assembly assembly)
        {
            ControllerLocator.AddAssemblyToScan(assembly);
            ViewLocator.AddAssemblyToScan(assembly);
        }

#if WINDOWS_PHONE
        public Tasks.ITaskManager TaskManager { get; private set; }
#endif

        public IActionInvoker ActionInvoker { get; private set; }
        public IViewLocator ViewLocator { get; private set; }
        public IControllerLocator ControllerLocator { get; private set; }
        public ITransientStore ApplicationTransientState { get; private set; }
        public IEventAggregator EventAggregator { get; private set; }
        public IErrorReporter ErrorReporter { get; private set; }
        public TaskScheduler AppScheduler { get; private set; }
        public Dispatcher AppDispatcher { get; private set; }
    }
}